package de.stefanocke.roo.wicket.model;

import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails;
import org.springframework.roo.classpath.scanner.MemberDetails;
import org.springframework.roo.model.JavaType;
import org.apache.commons.lang3.Validate;

public class JavaTypeMetadataDetails {
	private JavaType javaType;
	private String plural;
	private boolean isEnumType;
	private boolean isApplicationType;
	private ClassOrInterfaceTypeDetails classOrInterfaceTypeDetails;

	/**
	 * Constructor for JavaTypeMetadataDetails.
	 * 
	 * @param javaType
	 *            (must not be null)
	 * @param cid
	 * @param memberDetails
	 * @param plural
	 *            (must contain text)
	 * @param isEnumType
	 * @param isApplicationType
	 * @param persistenceDetails
	 *            (may be null if no persistence metadata is present for the
	 *            javaType)
	 */
	public JavaTypeMetadataDetails(JavaType javaType, ClassOrInterfaceTypeDetails cid, 
			String plural, boolean isEnumType, boolean isApplicationType) {
		Validate.notNull(javaType, "Java type required");
		Validate.notEmpty(plural, "Plural required");
		this.javaType = javaType;
		this.classOrInterfaceTypeDetails = cid;
		this.plural = plural;
		this.isEnumType = isEnumType;
		this.isApplicationType = isApplicationType;
	}

	/**
	 * Constructor to wrap non.application types into a JavaTypeMetadataDetails object.
	 * @param javaType
	 */
	public JavaTypeMetadataDetails(JavaType javaType){
		this.javaType = javaType;
	}
	public JavaType getJavaType() {
		return javaType;
	}

	public ClassOrInterfaceTypeDetails getClassOrInterfaceTypeDetails() {
		return classOrInterfaceTypeDetails;
	}

	public String getPlural() {
		return plural;
	}

	public boolean isEnumType() {
		return isEnumType;
	}

	public boolean isApplicationType() {
		return isApplicationType;
	}

	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (isApplicationType ? 1231 : 1237);
		result = prime * result + (isEnumType ? 1231 : 1237);
		result = prime * result + ((javaType == null) ? 0 : javaType.hashCode());
		result = prime * result + ((plural == null) ? 0 : plural.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JavaTypeMetadataDetails other = (JavaTypeMetadataDetails) obj;
		if (isApplicationType != other.isApplicationType)
			return false;
		if (isEnumType != other.isEnumType)
			return false;
		if (javaType == null) {
			if (other.javaType != null)
				return false;
		} else if (!javaType.equals(other.javaType))
			return false;
		if (plural == null) {
			if (other.plural != null)
				return false;
		} else if (!plural.equals(other.plural))
			return false;
		return true;
	}

}
